﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using MySQLDriverCS;
///
/// MySQL操作库
/// IP: 114.80.156.90
/// user: sq_hongquedb
///

namespace Common
{
    class DBOperator
    {
        private static MySQLConnection connection = new MySQLConnection(new MySQLConnectionString("114.80.156.90", "sq_hongquedb", "sq_hongquedb", "sq_hongquedb").AsString);
        
        private DBOperator()
		{
            
		}
        public static bool Initialize()
        {
            try
            {
                MessageBox.Show("Ini");
                connection.Open();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
            return true;
        }

        public static int ExecuteInsert(string sql)
        {
            //Debug.WriteLine(sql);
            MySQLCommand cmd = new MySQLCommand(sql, connection);
                try
                {
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = @"select LAST_INSERT_ID()";
                    int value = Int32.Parse(cmd.ExecuteScalar().ToString());
                    return value;
                }
                catch (Exception e)
                {
                    throw e;
                }
        }

        public static DataTable SelectTable(string sql)
        {
            MessageBox.Show("Show");
            DataTable db=null;
            return db;
        }

        public static bool CloseDB()
        {
            if (connection != null)
                connection.Close();
            return true;
        }
    }
}
